package com.credithc.customers.base.ro;

import com.credithc.customers.base.codes.CustomerCodes;
import com.credithc.customers.base.exception.CustomerException;
import com.credithc.customers.base.utils.CustomerUtils;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

/**
 * @description: 用户什么信息变更入参表
 * @author: fby
 * @date: 2020/1/20 15:27
 * @param: null
 * @return:
 */
@Data
public class CustomerUnifyUntieRo extends CustomerBaseRo {

    private String preCustomerNo;

    private String customerNo;

    private String accessToken;

    private CustomerIdInfoRo idInfo;

    public static void checkBaseParam(CustomerUnifyUntieRo ro) {
        if (StringUtils.isBlank(ro.getRequestNo())) {
            throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "请求流水号不能为空");
        }

        if (StringUtils.isBlank(ro.getAccessToken()) && ro.getIdInfo() == null) {
            throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "个人客户证件信息和accessToken不能同时为空");
        }
        if (ro.getIdInfo() != null) {
            if (StringUtils.isBlank(ro.getCustomerNo())) {
                throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "客户号不能为空");
            }
            CustomerUtils.checkIdCardNo(ro.getIdInfo().getIdCardNo());
            CustomerUtils.checkIdCard(ro.getIdInfo().getIdCardNo());
            CustomerUtils.checkCustomerName(ro.getIdInfo().getCustomerName());
            CustomerUtils.checkIdCardTypeAndNo(ro.getIdInfo().getIdCardNo(),ro.getIdInfo().getIdCardType());
        }
    }

}
